home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Misc / msql-1.0.6 / src / tests / killer < prev    next >
Text File  |  1995-05-28  |  9KB  |  435 lines

  1. #!/bin/sh
  2. #
  3. #  This is a killer test that produces timing results in msql.times
  4. #  It's run as "killer <dbName>" where dbName is an existing database
  5. #  in which it does it's thing.  It creates, drops and generally
  6. #  beats up on a table called "test" within the given database so
  7. #  run it somewhere that you don't have a test table.
  8. #
  9. #  You may need to change a couple of the definitions below depending
  10. #  on how you`re setup (eg "/var/adm/msqld.pid"  and  "bc -l")
  11. #
  12. #  The script tries to determine what sort of /bin/time you have and
  13. #  works properly with either a SysV or BSD styled time.
  14. #
  15. #                            Bambi
  16.  
  17.  
  18. CREATE_KEY="create table test ( name char(40), num int primary key)"
  19. CREATE_FLAT="create table test ( name char(40), num int)"
  20. DROP="drop table test"
  21. DELETE="delete from test"
  22.  
  23. TMP_FILE="/tmp/msql_test.out"
  24. RES_FILE="./msql.times"
  25.  
  26. DB=$1
  27. NUM_TESTS=3
  28. NUM_INSERTS=5000
  29. NUM_SELECTS=5000
  30.  
  31. CALC="bc -l"
  32. PID_FILE="/var/adm/msqld.pid"
  33.  
  34.  
  35.  
  36. PROFILE="N"
  37.  
  38.  
  39. if test "$DB." = "."
  40. then
  41.     echo 
  42.     echo "Bad usage.  Please read the intro to the script."
  43.     echo
  44.     exit 1
  45. fi
  46.  
  47. #
  48. # Print the output file header
  49. #
  50.  
  51. echo "mSQL Killer Test.     Test machine = `uname -a`" > $RES_FILE
  52. echo "------------------------------------------------------------" >> $RES_FILE
  53. echo >> $RES_FILE
  54. echo >> $RES_FILE
  55.  
  56. #
  57. # Try to find time.  Linux may have it in /usr/bin
  58. #
  59. if test -f /bin/time
  60. then
  61.     BIN_TIME="/bin/time"
  62. else
  63.     if test -f /usr/bin/time
  64.     then
  65.         BIN_TIME="/usr/bin/time"
  66.     else
  67.         if test -f /usr/sbin/time
  68.         then
  69.             BIN_TIME="/usr/sbin/time"
  70.         fi
  71.     fi
  72. fi
  73.  
  74. if test "$BIN_TIME." = "."
  75. then
  76.     echo "Can't find /bin/time, /usr/bin/time or /usr/sbin/time"
  77.     echo "Timing details ar not available"
  78.     BIN_TIME=""
  79.     echo "time not found.  No timing details available" >> $RES_FILE
  80.     echo >> $RES_FILE
  81.     echo >> $RES_FILE
  82. else
  83.     echo "Using $BIN_TIME for timing calculations"
  84.     $BIN_TIME --version >/dev/null  2>&1
  85.     if test $? -eq 0
  86.     then
  87.         echo "$BIN_TIME is actually GNU time.  Using --portability."
  88.         BIN_TIME="$BIN_TIME --portability"
  89.     fi
  90. fi
  91.  
  92.  
  93.  
  94. #
  95. # What sort of /bin/time do we have?
  96. #
  97.  
  98. if test `$BIN_TIME /bin/true 2>&1 | wc -l` -gt 1
  99. then
  100.     echo "$BIN_TIME produces System V styled output."
  101.     TIME_CALC="(grep -i \"^real\" | awk '{ print \$2 }')"
  102. else
  103.     echo "$BIN_TIME produces BSD styled output."
  104.     TIME_CALC="awk '{ print \$1 }'"
  105. fi
  106.  
  107.  
  108.  
  109. #########################################################################
  110. # Insert into a new keyed table
  111. #
  112.  
  113. COUNT=0
  114. rm -f $TMP_FILE
  115. TOTAL=0
  116. if test "$PROFILE." = "Y."
  117. then
  118.     kill -INT `cat $PID_FILE`
  119.     sleep 1
  120.     ../msql/msqld&
  121.     sleep 1
  122. fi
  123. echo "Inserting $NUM_INSERTS rows into new keyed table gave :-" >> $RES_FILE
  124. while test $COUNT -lt $NUM_TESTS
  125. do
  126.     echo "Dropping test table"
  127.     echo "$DROP \p\g" | (../msql/msql $DB > /dev/null)
  128.     echo "Creating keyed table"
  129.     echo "$CREATE_KEY \p\g" | (../msql/msql $DB > /dev/null)
  130.     echo "Inserting $NUM_INSERTS rows into keyed table"
  131.     $BIN_TIME ../msql/insert_test $DB $NUM_INSERTS 2> $TMP_FILE
  132.     if test $? -ne 0
  133.     then
  134.         echo
  135.         echo "Test failed!  Aborting."
  136.         echo
  137.         exit 1
  138.     fi
  139.     TIME=`(eval $TIME_CALC) < $TMP_FILE`
  140.     echo "    $TIME seconds real time" >> $RES_FILE
  141.     TOTAL=`echo "$TOTAL + $TIME" | $CALC`
  142.     COUNT=`expr $COUNT + 1`
  143.     echo "Inserts took $TIME seconds"
  144. done
  145.  
  146. echo >> $RES_FILE
  147. AVG=`echo "($NUM_INSERTS * $NUM_TESTS) / $TOTAL" | $CALC | sed "s/\..*//"`
  148. echo "    Total time = $TOTAL" >> $RES_FILE
  149. echo "    Average operations per second = $AVG" >> $RES_FILE
  150.  
  151. if test "$PROFILE." = "Y."
  152. then
  153.     kill -INT `cat $PID_FILE`
  154.     sleep 1
  155.     echo >> $RES_FILE
  156.     echo >> $RES_FILE
  157.     prof ../msql/msqld | head -10 >> $RES_FILE
  158. fi
  159.  
  160. echo >> $RES_FILE
  161. echo >> $RES_FILE
  162. echo >> $RES_FILE
  163. echo >> $RES_FILE
  164.  
  165.  
  166.  
  167.  
  168.  
  169. #########################################################################
  170. # Filling a deleted keyed table
  171. #
  172.  
  173. COUNT=0
  174. rm -f $TMP_FILE
  175. TOTAL=0
  176. if test "$PROFILE." = "Y."
  177. then
  178.     ../msql/msqld&
  179.     sleep 1
  180. fi
  181. echo "Filling a deleted keyed table with $NUM_INSERTS rows gave :-" >> $RES_FILE
  182. while test $COUNT -lt $NUM_TESTS
  183. do
  184.     echo "Deleting contents of keyed table"
  185.     echo "$DELETE \p\g" | (../msql/msql $DB > /dev/null)
  186.     echo "Filling data holes with $NUM_INSERTS inserts."
  187.     $BIN_TIME ../msql/insert_test $DB $NUM_INSERTS 2> $TMP_FILE
  188.     if test $? -ne 0
  189.     then
  190.         echo
  191.         echo "Test failed!  Aborting."
  192.         echo
  193.         exit 1
  194.     fi
  195.     TIME=`(eval $TIME_CALC) < $TMP_FILE`
  196.     echo "    $TIME seconds real time" >> $RES_FILE
  197.     TOTAL=`echo "$TOTAL + $TIME" | $CALC`
  198.     COUNT=`expr $COUNT + 1`
  199.     echo "Inserts took $TIME seconds."
  200. done
  201.  
  202. echo >> $RES_FILE
  203. AVG=`echo "($NUM_INSERTS * $NUM_TESTS) / $TOTAL" | $CALC| sed "s/\..*//"`
  204. echo "    Total time = $TOTAL" >> $RES_FILE
  205. echo "    Average operations per second = $AVG" >> $RES_FILE
  206.  
  207. if test "$PROFILE." = "Y."
  208. then
  209.     kill -INT `cat $PID_FILE`
  210.     sleep 1
  211.     echo >> $RES_FILE
  212.     echo >> $RES_FILE
  213.     prof ../msql/msqld | head -10 >> $RES_FILE
  214. fi
  215.  
  216. echo >> $RES_FILE
  217. echo >> $RES_FILE
  218. echo >> $RES_FILE
  219. echo >> $RES_FILE
  220.  
  221.  
  222.  
  223.  
  224.  
  225. #########################################################################
  226. # Selecting from a keyed table
  227. #
  228.  
  229. COUNT=0
  230. rm -f $TMP_FILE
  231. TOTAL=0
  232. if test "$PROFILE." = "Y."
  233. then
  234.     ../msql/msqld&
  235.     sleep 1
  236. fi
  237. echo "Selecting $NUM_SELECTS rows using primary key :-" >> $RES_FILE
  238. while test $COUNT -lt $NUM_TESTS
  239. do
  240.     echo "Selecting $NUM_SELECTS rows from a keyed table"
  241.     $BIN_TIME ../msql/select_test $DB $NUM_SELECTS 2> $TMP_FILE
  242.     if test $? -ne 0
  243.     then
  244.         echo
  245.         echo "Test failed!  Aborting."
  246.         echo
  247.         exit 1
  248.     fi
  249.     TIME=`(eval $TIME_CALC) < $TMP_FILE`
  250.     echo "    $TIME seconds real time" >> $RES_FILE
  251.     TOTAL=`echo "$TOTAL + $TIME" | $CALC`
  252.     COUNT=`expr $COUNT + 1`
  253.     echo "Selects took $TIME seconds"
  254. done
  255.  
  256. echo >> $RES_FILE
  257. AVG=`echo "($NUM_SELECTS * $NUM_TESTS) / $TOTAL" | $CALC| sed "s/\..*//"`
  258. echo "    Total time = $TOTAL" >> $RES_FILE
  259. echo "    Average operations per second = $AVG" >> $RES_FILE
  260.  
  261. if test "$PROFILE." = "Y."
  262. then
  263.     kill -INT `cat $PID_FILE`
  264.     sleep 1
  265.     echo >> $RES_FILE
  266.     echo >> $RES_FILE
  267.     prof ../msql/msqld | head -10 >> $RES_FILE
  268. fi
  269.  
  270. echo >> $RES_FILE
  271. echo >> $RES_FILE
  272. echo >> $RES_FILE
  273. echo >> $RES_FILE
  274.  
  275.  
  276.  
  277.  
  278.  
  279. #########################################################################
  280. # Insert into a new flat table
  281. #
  282.  
  283. COUNT=0
  284. rm -f $TMP_FILE
  285. TOTAL=0
  286. if test "$PROFILE." = "Y."
  287. then
  288.     ../msql/msqld&
  289.     sleep 1
  290. fi
  291. echo "Inserting $NUM_INSERTS rows into new flat table gave :-" >> $RES_FILE
  292. while test $COUNT -lt $NUM_TESTS
  293. do
  294.     echo "Dropping test table"
  295.     echo "$DROP \p\g" | (../msql/msql $DB > /dev/null)
  296.     echo "Creating flat table"
  297.     echo "$CREATE_FLAT \p\g" | (../msql/msql $DB > /dev/null)
  298.     echo "Inserting $NUM_INSERTS rows into flat table"
  299.     $BIN_TIME ../msql/insert_test $DB $NUM_INSERTS 2> $TMP_FILE
  300.     if test $? -ne 0
  301.     then
  302.         echo
  303.         echo "Test failed!  Aborting."
  304.         echo
  305.         exit 1
  306.     fi
  307.     TIME=`(eval $TIME_CALC) < $TMP_FILE`
  308.     echo "    $TIME seconds real time" >> $RES_FILE
  309.     TOTAL=`echo "$TOTAL + $TIME" | $CALC`
  310.     COUNT=`expr $COUNT + 1`
  311.     echo "Inserts took $TIME seconds."
  312. done
  313.  
  314. echo >> $RES_FILE
  315. AVG=`echo "($NUM_INSERTS * $NUM_TESTS) / $TOTAL" | $CALC| sed "s/\..*//"`
  316. echo "    Total time = $TOTAL" >> $RES_FILE
  317. echo "    Average operations per second = $AVG" >> $RES_FILE
  318.  
  319. if test "$PROFILE." = "Y."
  320. then
  321.     kill -INT `cat $PID_FILE`
  322.     sleep 1
  323.     echo >> $RES_FILE
  324.     echo >> $RES_FILE
  325.     prof ../msql/msqld | head -10 >> $RES_FILE
  326. fi
  327.  
  328. echo >> $RES_FILE
  329. echo >> $RES_FILE
  330. echo >> $RES_FILE
  331. echo >> $RES_FILE
  332.  
  333.  
  334. #########################################################################
  335. # Filling a flat table
  336. #
  337.  
  338. COUNT=0
  339. rm -f $TMP_FILE
  340. TOTAL=0
  341. if test "$PROFILE." = "Y."
  342. then
  343.     ../msql/msqld&
  344.     sleep 1
  345. fi
  346. echo "Filling a deleted flat table with $NUM_INSERTS rows gave :-" >> $RES_FILE
  347. while test $COUNT -lt $NUM_TESTS
  348. do
  349.     echo "Deleting contents of flat table"
  350.     echo "$DELETE \p\g" | (../msql/msql $DB > /dev/null)
  351.     echo "Filling data holes with $NUM_INSERTS inserts."
  352.     $BIN_TIME ../msql/insert_test $DB $NUM_INSERTS 2> $TMP_FILE
  353.     if test $? -ne 0
  354.     then
  355.         echo
  356.         echo "Test failed!  Aborting."
  357.         echo
  358.         exit 1
  359.     fi
  360.     TIME=`(eval $TIME_CALC) < $TMP_FILE`
  361.     echo "    $TIME seconds real time" >> $RES_FILE
  362.     TOTAL=`echo "$TOTAL + $TIME" | $CALC`
  363.     COUNT=`expr $COUNT + 1`
  364.     echo "Inserts took $TIME seconds"
  365. done
  366.  
  367. echo >> $RES_FILE
  368. AVG=`echo "($NUM_INSERTS * $NUM_TESTS) / $TOTAL" | $CALC| sed "s/\..*//"`
  369. echo "    Total time = $TOTAL" >> $RES_FILE
  370. echo "    Average operations per second = $AVG" >> $RES_FILE
  371.  
  372. if test "$PROFILE." = "Y."
  373. then
  374.     kill -INT `cat $PID_FILE`
  375.     sleep 1
  376.     echo >> $RES_FILE
  377.     echo >> $RES_FILE
  378.     prof ../msql/msqld | head -10 >> $RES_FILE
  379. fi
  380.  
  381. echo >> $RES_FILE
  382. echo >> $RES_FILE
  383. echo >> $RES_FILE
  384. echo >> $RES_FILE
  385.  
  386.  
  387.  
  388. #########################################################################
  389. # Selecting from a flat table
  390. #
  391.  
  392. COUNT=0
  393. rm -f $TMP_FILE
  394. TOTAL=0
  395. if test "$PROFILE." = "Y."
  396. then
  397.     ../msql/msqld&
  398.     sleep 1
  399. fi
  400. echo "Selecting $NUM_SELECTS rows without a key :-" >> $RES_FILE
  401. while test $COUNT -lt $NUM_TESTS
  402. do
  403.     $BIN_TIME ../msql/select_test $DB $NUM_SELECTS 2> $TMP_FILE
  404.     if test $? -ne 0
  405.     then
  406.         echo
  407.         echo "Test failed!  Aborting."
  408.         echo
  409.         exit 1
  410.     fi
  411.     TIME=`(eval $TIME_CALC) < $TMP_FILE`
  412.     echo "    $TIME seconds real time" >> $RES_FILE
  413.     TOTAL=`echo "$TOTAL + $TIME" | $CALC`
  414.     COUNT=`expr $COUNT + 1`
  415. done
  416.  
  417. echo >> $RES_FILE
  418. AVG=`echo "($NUM_SELECTS * $NUM_TESTS) / $TOTAL" | $CALC| sed "s/\..*//"`
  419. echo "    Total time = $TOTAL" >> $RES_FILE
  420. echo "    Average operations per second = $AVG" >> $RES_FILE
  421.  
  422. if test "$PROFILE." = "Y."
  423. then
  424.     kill -INT `cat $PID_FILE`
  425.     sleep 1
  426.     echo >> $RES_FILE
  427.     echo >> $RES_FILE
  428.     prof ../msql/msqld | head -10 >> $RES_FILE
  429. fi
  430.  
  431. echo >> $RES_FILE
  432. echo >> $RES_FILE
  433. echo >> $RES_FILE
  434. echo >> $RES_FILE
  435.